package m2.connector;
import m2.role.ProvidedRole;
import m2.role.RequiredRole;

public class Connector{

        private Glue glueIn;
        private Glue glueOut;
       
        private ConnectorInterface connectorInterface;
       
        /**
         * 
         */
        public Connector(){
                connectorInterface = new ConnectorInterface();
        }
       
        /**
         * 
         * @param glue
         */
        public final void addGlueIn(Glue glue){
                this.glueIn = glue;
        }
        
        /**
         * 
         * @param glue
         */
        public final void addGlueOut(Glue glue){
            this.glueOut = glue;
        }
       
        /**
         * 
         * @param roles
         */
        public final void addRequiredRole(RequiredRole ... roles){
                for (RequiredRole role : roles){
                        role.setOwner(this.getClass().getSimpleName());
                        role.setType("RequiredRole");
                        connectorInterface.getListeRequiredRole().add(role);
                }
        }
       
        /**
         * 
         * @param roles
         */
        public final void addProvidedRole(ProvidedRole ... roles){
                for (ProvidedRole role : roles){
                        role.setOwner(this.getClass().getSimpleName());
                        role.setType("ProvidedRole");
                        connectorInterface.getListeProvidedRole().add(role);
                }
        }
       
        /**
         * 
         * @param name
         * @return
         */
        public RequiredRole getRequiredRole(String name){
                for (RequiredRole role : connectorInterface.getListeRequiredRole()){
                        if (role.getRoleValue().equals(name)){
                                return role;
                        }
                }
                return null;
        }
       
        /**
         * 
         * @param name
         * @return
         */
        public ProvidedRole getProvidedRole(String name){
                for (ProvidedRole role : connectorInterface.getListeProvidedRole()){
                        if (role.getRoleValue().equals(name)){
                                return role;
                        }
                }
                return null;
        }
       
        /**
         * 
         * @return
         */
        public Glue getGlueIn() {
                return glueIn;
        }
        
        /**
         * 
         * @return
         */
        public Glue getGlueOut() {
            return glueOut;
        }
        
}
